<template>
  <star-horse-dialog :visible = "batchDialogTableVisible" :title = "dialogTitle" is-batch = "true" @merge = "merge"
                     @mergeDraft = "mergeDraft"
                     @reset = "resetForm">

    <el-table
        :data = "batchDataList"
        :row-class-name = "rowClassName"
        @selection-change = "handleDetailSelectionChange"
        border
        fit = "true"
        ref = "tb"
        v-loading = "loading"
    >
      <el-table-column align = "center" type = "selection" width = "30"/>
      <el-table-column align = "center" label = "序号" prop = "xh" width = "50"></el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "主键"
          min-width = "200px"
          prop = "idDepartment"
          required
          sortable v-if = " false ">
        <template #default = "scope">
          <el-input-number clearable placeholder = "请输入主键"
                           v-model = "batchDataList[scope.row.xh-1].idDepartment"/>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "部门名称"
          min-width = "200px"
          prop = "deptName"
          required
          sortable v-if = "true ">
        <template #default = "scope">
          <el-input clearable placeholder = "请输入部门名称"
                    v-model = "batchDataList[scope.row.xh-1].deptName"></el-input>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "部门编码"
          min-width = "200px"
          prop = "deptCode"
          required
          sortable v-if = "true ">
        <template #default = "scope">
          <el-input clearable placeholder = "请输入部门编码"
                    v-model = "batchDataList[scope.row.xh-1].deptCode"></el-input>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "部门描述"
          min-width = "200px"
          prop = "deptDesc"
          required
          sortable v-if = "true ">
        <template #default = "scope">
          <el-input clearable placeholder = "请输入部门描述"
                    v-model = "batchDataList[scope.row.xh-1].deptDesc"></el-input>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "修改人"
          min-width = "200px"
          prop = "updatedBy"
          sortable
          v-if = " false ">
        <template #default = "scope">
          <el-input clearable placeholder = "请输入修改人"
                    v-model = "batchDataList[scope.row.xh-1].updatedBy"></el-input>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "修改日期"
          min-width = "200px"
          prop = "updatedDate"
          sortable
          v-if = " false ">
        <template #default = "scope">
          <el-date-picker clearable placeholder = "请选择修改日期"
                          type = "date"
                          v-model = "batchDataList[scope.row.xh-1].updatedDate">
          </el-date-picker>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "创建人"
          min-width = "200px"
          prop = "createdBy"
          sortable
          v-if = " false ">
        <template #default = "scope">
          <el-input clearable placeholder = "请输入创建人"
                    v-model = "batchDataList[scope.row.xh-1].createdBy"></el-input>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "创建日期"
          min-width = "200px"
          prop = "createdDate"
          sortable
          v-if = " false ">
        <template #default = "scope">
          <el-date-picker clearable placeholder = "请选择创建日期"
                          type = "date"
                          v-model = "batchDataList[scope.row.xh-1].createdDate">
          </el-date-picker>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "是否删除 1 是 0否"
          min-width = "200px"
          prop = "isDel"
          sortable
          v-if = " false ">
        <template #default = "scope">
          <el-input-number clearable placeholder = "请输入是否删除 1 是 0否"
                           v-model = "batchDataList[scope.row.xh-1].isDel"/>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "状态编码"
          min-width = "200px"
          prop = "statusCode"
          sortable
          v-if = " false ">
        <template #default = "scope">
          <el-input clearable placeholder = "请输入状态编码"
                    v-model = "batchDataList[scope.row.xh-1].statusCode"></el-input>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "系统编号"
          min-width = "200px"
          prop = "dataNo"
          sortable
          v-if = " false ">
        <template #default = "scope">
          <el-input clearable placeholder = "请输入系统编号"
                    v-model = "batchDataList[scope.row.xh-1].dataNo"></el-input>
        </template>
      </el-table-column>
    </el-table>

  </star-horse-dialog>

  <star-horse-dialog :visible = "dialogTableVisible" :title = "dialogTitle" @merge = "merge" @mergeDraft = "mergeDraft"
                     @reset = "resetForm">
    <el-form :model = "ruleForm" :rules = "rules" class = "demo-ruleForm" ref = "ruleForm">
      <el-form-item label = "主键" prop = "idDepartment" v-if = "false">
        <el-input clearable placeholder = "请输入主键"
                  v-model = "ruleForm.idDepartment"></el-input>
      </el-form-item>

      <el-form-item label = "部门名称" prop = "deptName"
                    required v-if = "!false">
        <el-input clearable placeholder = "请输入部门名称"
                  v-model = "ruleForm.deptName"></el-input>
      </el-form-item>

      <el-form-item label = "部门编码" prop = "deptCode"
                    required v-if = "!false">
        <el-input clearable placeholder = "请输入部门编码"
                  v-model = "ruleForm.deptCode"></el-input>
      </el-form-item>

      <el-form-item label = "部门描述" prop = "deptDesc"
                    required v-if = "!false">
        <el-input clearable placeholder = "请输入部门描述"
                  v-model = "ruleForm.deptDesc"></el-input>
      </el-form-item>

      <el-form-item label = "修改人" prop = "updatedBy"
                    v-if = "!true">
        <el-input clearable placeholder = "请输入修改人"
                  v-model = "ruleForm.updatedBy"></el-input>
      </el-form-item>

      <el-form-item label = "修改日期" prop = "updatedDate"
                    v-if = "!true">
        <el-date-picker clearable placeholder = "请选择修改日期" type = "date"
                        v-model = "ruleForm.updatedDate">
        </el-date-picker>
      </el-form-item>

      <el-form-item label = "创建人" prop = "createdBy"
                    v-if = "!true">
        <el-input clearable placeholder = "请输入创建人"
                  v-model = "ruleForm.createdBy"></el-input>
      </el-form-item>

      <el-form-item label = "创建日期" prop = "createdDate"
                    v-if = "!true">
        <el-date-picker clearable placeholder = "请选择创建日期" type = "date"
                        v-model = "ruleForm.createdDate">
        </el-date-picker>
      </el-form-item>

      <el-form-item label = "是否删除 1 是 0否" prop = "isDel"
                    v-if = "!true">
        <el-input-number clearable placeholder = "请输入是否删除 1 是 0否"
                         v-model = "ruleForm.isDel"/>
      </el-form-item>

      <el-form-item label = "状态" prop = "statusCode"
                    v-if = "!false">
        <el-select placeholder = "请选择状" v-model = "ruleForm.statusCode">
          <el-option
              :key = "sitem.statusCode"
              :label = "sitem.statusName"
              :value = "sitem.statusCode"
              clearable
              v-for = "sitem in selectData"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label = "系统编号" prop = "dataNo"
                    v-if = "!true">
        <el-input clearable placeholder = "请输入系统编号"
                  v-model = "ruleForm.dataNo"></el-input>
      </el-form-item>
    </el-form>
  </star-horse-dialog>
  <star-horse-dialog :visible = "viewVisible" :title = "'查看数据'" :is-view = "true">

    <div class = "item">
      <label>部门名称:</label>
      <div class = "content">{{ ruleForm.deptName }}</div>
    </div>
    <div class = "item">
      <label>部门编码:</label>
      <div class = "content">{{ ruleForm.deptCode }}</div>
    </div>
    <div class = "item">
      <label>部门描述:</label>
      <div class = "content">{{ ruleForm.deptDesc }}</div>
    </div>
    <div class = "item">
      <label>状态名称:</label>
      <div class = "content">{{ ruleForm.statusName }}</div>
    </div>
    <div class = "item">
      <label>创建人:</label>
      <div class = "content">{{ ruleForm.createdBy }}</div>
    </div>
    <div class = "item">
      <label>创建日期:</label>
      <div class = "content">{{ createDate(ruleForm.createdDate) }}</div>
    </div>
  </star-horse-dialog>

  <el-card class = "inner_content">
    <el-form class = "search_area" size = "default">
      <el-form-item label = "部门名称">
        <el-input placeholder = "请输入部门名称" v-model = "searchForm.deptName"/>
      </el-form-item>
      <el-form-item label = "添加时间">
        <el-date-picker
            end-placeholder = "结束日期" placeholder = "请选择添加时间"
            range-separator = "到"
            start-placeholder = "开始日期"
            type = "daterange"
            v-model = "searchForm.createdDate"
        />
      </el-form-item>
      <el-form-item label = "     ">
        <el-button @click = "dataSearch" link type = "primary">
          <user-icon icon = "search"/>
          <span style = "vertical-align: middle;"> 查询 </span>
        </el-button>
        <el-button @click = "dataSearch(1)" link small>
          <span style = "vertical-align: middle;"> 重置 </span>
        </el-button>
      </el-form-item>
    </el-form>
    <el-divider/>


    <star-horse-button-list
        :permission = "permission"
        :upload-url = "uploadUrl"
        @upload = "upload"
        @uploadProcess = "uploadProcess"
        @uploadError = "uploadError"
        @uploadSuccess = "uploadProcess"
        @btnOperation = "btnOperation"
    />
    <el-table
        :data = "dataList"
        :row-key = "getRowIdentity"
        @row-dblclick = "editData"
        @selection-change = "handleSelectionChange"
        border
        class = "data_table"
        fit = "true"
        highlight-current-row = "true"
        id = "departmentPo"
        ref = "multipleTable"
        stripe = "true">
      <el-table-column fixed width = "1"/>
      <el-table-column
          :reserve-selection = "true"
          align = "center"
          fixed = "left"
          type = "selection"
      />
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "主键"
          min-width = "200px"
          prop = "idDepartment"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "部门名称"
          min-width = "200px"
          prop = "deptName"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "部门编码"
          min-width = "200px"
          prop = "deptCode"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "部门描述"
          min-width = "200px"
          prop = "deptDesc"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "修改人"
          min-width = "200px"
          prop = "updatedBy"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "修改日期"
          min-width = "200px"
          prop = "updatedDate"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "创建人"
          min-width = "200px"
          prop = "createdBy"
          sortable
          v-if = " true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "创建日期"
          min-width = "200px"
          prop = "createdDate"
          sortable
          v-if = " true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "是否删除 1 是 0否"
          min-width = "200px"
          prop = "isDel"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "状态编码"
          min-width = "200px"
          prop = "statusCode"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "系统编号"
          min-width = "200px"
          prop = "dataNo"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column fixed = "right" label = "操作" min-width = "180px">
        <template #default = "scope">
          <el-button v-if = "permission.edit" @click = "editById(scope.row[primaryKey])" link title = ""
                     type = "primary">
            <el-tooltip content = "编辑">编辑</el-tooltip>
          </el-button>
          <el-button v-if = "permission.view" @click = "viewById(scope.row[primaryKey])" link title = ""
                     type = "primary">
            <el-tooltip content = "查看">查看</el-tooltip>
          </el-button>
          <el-button v-if = "permission.delete" @click = "deleteById(scope.row[primaryKey])" link title = ""
                     type = "danger">
            <el-tooltip content = "删除">删除</el-tooltip>
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-divider/>
    <el-pagination
        :total = "totalData"
        @current-change = "pageChangeClick"
        @size-change = "pageSizeClick"
        layout = "total, sizes, prev, pager, next, jumper"
        v-model:currentPage = "currentPage"
        v-model:page-size = "pageSize"
        v-model:pageCount = "totalPage"/>

  </el-card>
</template>
<style>
</style>
<script>
import {common} from "../../api/common";
import {ref} from "vue";


export default {
  name: "DepartmentEntity",

  mixins: [common],
  setup() {
    return {}
  },
  data() {
    const loadByPageUrl = ref("/system-config/system/departmentEntity/pageList");
    const mergeUrl = ref("/system-config/system/departmentEntity/merge");
    const mergeDraftUrl = ref("/system-config/system/departmentEntity/mergeDraft");
    const batchMergeUrl = ref("/system-config/system/departmentEntity/mergeBatch");
    const batchMergeDraftUrl = ref("/system-config/system/departmentEntity/mergeBatchDraft");
    const loadByIdUrl = ref("/system-config/system/departmentEntity/getById");
    const deleteUrl = ref("/system-config/system/departmentEntity/batchDeleteById");
    const exportAllUrl = ref("/system-config/system/departmentEntity/exportData");
    const uploadUrl = "/system-config/system/departmentEntity/importData";
    const downloadTemplateUrl = ref("/system-config/system/departmentEntity/downloadTemplate");
    const primaryKey = "idDepartment";
    return {
      uploadUrl,
      loadByPageUrl,
      mergeUrl,
      mergeDraftUrl,
      batchMergeUrl,
      batchMergeDraftUrl,
      loadByIdUrl,
      deleteUrl,
      exportAllUrl,
      downloadTemplateUrl,
      primaryKey,
      rules: {
        deptName: [{required: true, message: "必选项不能为空", trigger: "blur"}],
        deptCode: [{required: true, message: "必选项不能为空", trigger: "blur"}],
        deptDesc: [{required: true, message: "必选项不能为空", trigger: "blur"}],
      }
    }
  },
  methods: {
    dataFormat(row, column, cellValue, index) {
      cellValue = this.commonDataFormat(row, column, cellValue, index);


      return cellValue;

    },
    /**
     * 初始化数据
     */
    init: function () {
      this.dataList = [];
      this.selectData = [];
      this.loadByPage(this.currentPage, this.pageSize);
      this.loadPermissionResources();
      this.loadSelectData();

    },

    /**
     * 状态码数据
     */
    loadSelectData() {
      this.commonSelectData("sys_department");
    }
    ,
    parseSearchData: function () {
      let data = this.searchForm;
      let arr = [];
      if (data.deptName) {
        arr.push({
          propertyName: "deptName",
          value: data.deptName,
          operation: "lk"
        });
      }
      if (data.createdDate) {
        arr.push({
          propertyName: "createdDate",
          value: data.createdDate,
          operation: "bt"
        });
      }
      return arr;
    }

  },
  created() {
    this.init();
  }
}
</script>